/**
 * 节气计算(公历)  支持(公历):[1900-1-1, 2100-12-31]
 * @param y int|string 公历年
 * @param n int|string 月或节气  根据参数x=null?节气取公历:月份
 * 		月:0-12,0=整年,>0:月份,1开始  节气:$.__dateMoonTerm索引
 * @param x int|string|null 公历日  null:节气取公历->n为节气索引
 * 		int|string: 公历日期取节气  x=0或日期,  n为月(0未取整年)
 * 			0:取整月节气  >0:日,取年月日的节气名(非节气返回null)
 * @return array|object|string|null  null:参数异常
 * 		节气取公历日期: array [chs,y:int,m:int,d:int]  m:1开始
 * 		取整年或月节气: object {'Y-M-D':chs}
 * 		取年月日节气名: string 中文节气名  非节气null,可用于判断
 */
$.dateMoonTerm = function(y, n=null, x=null){
	const NAME=$.__dateMoonTerm, T4=v=>$.pad($.s64.indexOf(v).toString(4),3);
	const BASE=[4,19,3,18,4,19,4,19,4,20,4,20,6,22,6,22,6,22,7,22,6,21,6,21];
	const DATA=( //region reg 64=>4进制24位  每位对应NAME索引的偏移BASE加的日期
		'bQMQMPgb,fQQgcggf,gQgkgggg,glhkhkgg,wgMQMPgb,fQQgcggf,gQgggggg,glhkhkgg,wgMQMPgb,fQQgcggf,' //1900-1909
		+'gQgggggg,glhkhkgg,wgMQMPgb,bQQgcggf,fQQggggg,ghgkgkgg,ggMQMPQL,bQQQcfgb,fQQggggf,ghgkgkgg,'//1910-1919
		+'ggMQMPQL,bQMQcfgb,fQQggggf,gQgkgkgg,ggMQMPQL,bQMQcfgb,fQQgcggf,gQgkgggg,ggMPMPLL,bQMQMPgb,'//1920-1929
		+'fQQgcggf,gQgkgggg,ggMPMPLL,bQMQMPgb,fQQgcggf,gQgggggg,ggMPMPLL,bQMQMPgb,fQQgcggf,gQgggggg,'//1930-1939
		+'ggMPMPLL,bQMQMPgb,fQQgcggf,gQgggggg,ggLPMPLL,bQMQMPQL,bQQgcfgf,fQQggggg,gcLPLPLL,LQMQMPQL,'//1940-1949
		+'bQMQcfgf,fQQggggg,gcLPLPLL,LQMQMPQL,bQMQcfgb,fQQgcggf,gbLPLPLL,LQMQMPQL,bQMQMPgb,fQQgcggf,'//1950-1959
		+'gLLPLLLL,LQMPMPLL,bQMQMPgb,fQQgcggf,gLLPLLLL,LQMPMPLL,bQMQMPgb,fQQgcggf,gLLLLLLL,LQMPMPLL,'//1960-1969
		+'bQMQMPgb,fQQgcggf,gLLLLLLL,LQLPMPLL,bQMQMPgb,fQQgcfgf,gL5LLLLL,LQLPLPLL,bQMQMPQb,fQQQcfgf,'//1970-1979
		+'gL5LLLLL,LQLPLPLL,bQMQMPQL,bQMQcfgf,fL5LHLLL,LMLPLPLL,LQMQMPQL,bQMQMfgb,fL5LHLLK,LLLPLLLL,'//1980-1989
		+'LQMPMPQL,bQMQMPgb,fL5LHLLK,L5LPLLLL,LQMPMPLL,bQMQMPgb,fL5LHLLK,L5LLLLLL,LQMPMPLL,bQMQMPgb,'//1990-1999
		+'fL5LHLLK,L5LLLLLL,LQMPMPLL,bQMQMPgb,fL5LHLLK,L5LLLLLL,LQLPLPLL,bQMQMPgb,fL5LHKLK,L55LLLLL,'//2000-2009
		+'LQLPLPLL,bQMQMPQb,fL55HKLK,L55LHLLL,LQLPLPLL,bQMQMPQL,bL15HKLK,K55LHLLL,LMLPLPLL,LQMPMPQL,'//2010-2019
		+'bL1514LK,K55LHLLK,LLLPLLLL,LQMPMPQL,bL1514LG,K55LHLLK,L5LLLLLL,LQMPMPLL,bL1514LG,K55LHLLK,'//2020-2029
		+'L5LLLLLL,LQMPMPLL,bL1514LG,K55LHLLK,L5LLLLLL,LQLPLPLL,bL1514LG,K55LHLLK,L5LLLLLL,LQLPLPLL,'//2030-2039
		+'bL1514LG,K555HKLK,L55LLLLL,LQLPLPLL,bL15145G,K515HKLK,L55LHLLL,LQLPLPLL,bL141450,G51514LK,'//2040-2049
		+'K55LHLLL,LLLPLLLL,LL141450,G51514LK,K55LHLLL,LLLLLLLL,LL141450,G51514LG,K55LHLLK,LLLLLLLL,'//2050-2059
		+'LL141400,G51514LG,K55LHLLK,L5LLLLLL,LL141400,G51514LG,K55LHLLK,L5LLLLLL,LL040400,G51514LG,'//2060-2069
		+'K555HKLK,L5LLLLLL,LL040400,G515145G,K555HKLK,L55LHLLL,LL040400,G515145G,K5151KLK,L55LHLLL,'//2070-2079
		+'LL040400,G5141450,K51514LK,K55LHLLL,LG040000,05141450,G51514LK,K55LHLLL,LG000000,05141450,'//2080-2089
		+'G51514LG,K55LHLLK,LG000000,05141400,G51514LG,K55LHLLK,L0000000,05140400,G51514LG,K55LHLLK,'//2090-2099
		+'L5LLLLLL' //endregion 2100
	).split(',').map(v=>$.pad(v.split('').map(T4).join(''),24));
	const FMT = function(v){ return v>9 ? v : '0'+v; };
	const DAY = function(i,x){ return DATA[i].slice(x,x+1)*1+BASE[x]; };
	const YMX = function(M,y,m){
		let x=y+'-'+FMT(m)+'-', i=(m-1)*2;  y-=1900;
		M[x+FMT(DAY(y,i))]=NAME[i]; M[x+FMT(DAY(y,i=i+1))]=NAME[i];
	};
	$.dateMoonTerm = function(y, n, x=null){
		if(!(y*=1) || y<1900 || y>2100) return null;
		if(x===null){
			if((n*=1)!==n || n<0 || n>23) return null;
			return [NAME[n], y, Math.floor(n/2)+1, DAY(y-1900,n)];
		}
		if(n===0){ let M={},m=1; for(; m<13; m++) YMX(M,y,m); return M; }
		if((n*=1)!==n || n<1 || n>12) return null;  let R={}; YMX(R,y,n);
		return x*1===0 ? R : (R[y+'-'+FMT(n)+'-'+FMT(x)]||null);
	};
	return $.dateMoonTerm(y, n, x);
};
Object.defineProperty($,'__dateMoonTerm',{
	value: [
		'小寒','大寒','立春','雨水','惊蛰','春分',//0-5
		'清明','谷雨','立夏','小满','芒种','夏至',//6-11
		'小暑','大暑','立秋','处暑','白露','秋分',//12-17
		'寒露','霜降','立冬','小雪','大雪','冬至',//18-23
	],
});
